﻿using Aspose.Words;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

namespace SmartHelper
{
    public class WordHelper
    {
        #region Aspose
        public static void PrintByAspose(string filePath)
        {
            Document doc = new Document(@"c:\1.doc");
            doc.Print();
        }
        public static void Export(string filePath)
        {
        }
        public static bool SaveByAspose(string filePath, string saveFilePath)
        {
            Document doc = new Document(filePath);
            if (doc.Range.Bookmarks["Rhythmk"] != null)
            {
                Bookmark mark = doc.Range.Bookmarks["Rhythmk"];
                mark.Text = "张三公司";
            }
            doc.Save(saveFilePath, SaveFormat.Doc);  //保存为doc，并打开
            return true;
        }
        public static string Read(string filePath)
        {
            Document doc = new Document(filePath);
            return doc.GetText();
        }

        public static string ReadFromUrl(string url)
        {
            WebClient webclient = new WebClient();
            using (Stream stream = webclient.OpenRead(url))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    stream.CopyTo(ms);
                    Document doc = new Document(ms);
                    return doc.GetText();
                }
            }
        }
        #endregion


    }
}
